import java.io.*;
import java.net.Socket;

public class Client {
    public static void main(String[] args) {
        Socket socket = null;
        OutputStream outputStream = null;
        InputStream inputStream = null;
        File file = new File("Client.jpg");
        File file1 = new File("Test.txt");
        FileOutputStream fileOutputStream = null;
        FileInputStream fileInputStream = null;
        try {
            socket = new Socket("127.0.0.1",3456);
            inputStream = socket.getInputStream();
            fileOutputStream = new FileOutputStream(file);
            byte[] b =new byte[10000];
            int length = inputStream.read(b);
            while (length!=-1){
                String str = new String(b,0,length);
                System.out.println(str);
                fileOutputStream.write(b,0,length);
                break;
            }
            socket.shutdownInput();

            outputStream = socket.getOutputStream();

            outputStream.write("我是客户端，我已经收到图片了，谢谢！".getBytes());
            outputStream.write("我是客户端正在向服务端发送图片！".getBytes());
            fileInputStream = new FileInputStream(file1);
            byte[] t = new byte[10000];
            int length1= fileInputStream.read(t);
            while (length1!=-1){
                outputStream.write(t,0,length1);
            }

            socket.shutdownOutput();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
